import Vue from 'vue'
import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-default/index.css'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import VueRouter from 'vue-router'

Vue.use(ElementUI);
Vue.use(VueRouter);

import routes  from './routes'


const  router = new VueRouter({
    routes
});



router.beforeEach((to, from, next) => {
    const adminReg = RegExp(/admin/);
    const readerReg = RegExp(/reader/);
    if(to.path.match(adminReg) ||to.path === "/"){
        if (to.path === '/admin/login') {
            sessionStorage.removeItem('adminName');
        }
        /*    let adminName = JSON.parse(sessionStorage.getItem('adminName'));*/
        let adminName = sessionStorage.getItem('adminName');
        if (!adminName && to.path !== '/admin/login') {
            next({ path: '/admin/login' })
        } else {
            next()
        }
    } else if (to.path.match(readerReg)) {
        next();
    }


})




new Vue({
   // el: '#app',
    router,
    render: h => h(App)
}).$mount('#app');
